package com.wxtwxt.ruralmall.search.controller;

import com.wxtwxt.ruralmall.common.to.SkuEsModel;
import com.wxtwxt.ruralmall.common.utils.BizCodeEnum;
import com.wxtwxt.ruralmall.common.utils.R;
import com.wxtwxt.ruralmall.search.service.ProductSaveService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @author Wxt
 * @create 2023-03-15 11:18
 */
@RestController
@RequestMapping("/search/save")
public class ElasticSaveController {
    @Resource
    private ProductSaveService productSaveService;

    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        Boolean flag = false;
        try {
            flag = productSaveService.productStatusUp(skuEsModels);
        }catch (Exception e) {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if(flag) {
            return R.error();
        }else {
            return R.ok();
        }
    }
}
